package com.yuwj.chinaa.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.yuwj.chinaa.R;
import com.yuwj.chinaa.base.BaseActivity;

import java.util.Timer;
import java.util.TimerTask;

import butterknife.OnClick;

/**
 * 欢迎页
 */
public class WelcomeActivity extends BaseActivity {

    Timer timer;

    public static Intent createIntent(Context context) {
        return new Intent(context, WelcomeActivity.class);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 解决之前打开过的应用,按home键后,从主页面点击图标进入应用会重新打开一遍的问题.详见http://blog.csdn.net/busjb/article/details/40891239
        if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
            finish();
            return;
        }
        timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        startActivity(LoginActivity.createIntent(context));
                        finish();
                    }
                });
            }
        }, 2000);
    }

    @Override
    public int setCustomContentViewResourceId() {
        return R.layout.activity_welcome;
    }

    @Override
    public void initParam() {
    }

    @Override
    public void initView() {
    }

    @Override
    public void initOperator() {

    }

    @OnClick({R.id.tv_jump})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_jump:
                startActivity(LoginActivity.createIntent(context));
                finish();
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (timer != null) {
            timer.cancel();
            timer = null;
        }
    }
}
